<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="700" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="选择会员" prop="remark">
				<!-- <jd-table-select v-model="value2" :apiObj="apiObj" :params="params" :table-width="550" :props="props" @change="change">
					<el-table-column prop="id" label="ID" width="180"></el-table-column>
					<el-table-column prop="user" label="姓名"></el-table-column>
				</jd-table-select> -->
				<jd-table-select v-model="value" :apiObj="apiObj" :table-width="550" multiple clearable collapse-tags collapse-tags-tooltip :props="props" @change="change">
					<template #header="{form, submit}">
						<el-form :inline="true" :model="form">
							<el-form-item>
								<el-select v-model="form.sex" placeholder="性别" clearable :teleported="false">
									<el-option label="男" value="1"></el-option>
									<el-option label="女" value="2"></el-option>
								</el-select>
							</el-form-item>
							<!-- <el-form-item>
								<el-date-picker v-model="form.date" value-format="YYYY-MM-DD" type="date" placeholder="注册时间" :teleported="false"></el-date-picker>
							</el-form-item> -->
							<el-form-item>
								<el-button type="primary" @click="submit">查询</el-button>
							</el-form-item>
						</el-form>
					</template>
					<el-table-column prop="id" label="ID" width="180"></el-table-column>
					<el-table-column prop="user" label="姓名" width="100"></el-table-column>
					<el-table-column prop="time" label="注册时间"></el-table-column>
				</jd-table-select>
			</el-form-item>
			<el-form-item label="岗位名称" prop="postName">{{ value }}
				<el-input v-model="form.postName" clearable></el-input>
			</el-form-item>
			<el-form-item label="岗位别名" prop="postCode">
				<el-input v-model="form.postCode" clearable></el-input>
			</el-form-item>
			<el-form-item label="备注" prop="remark">
				<el-input v-model="form.remark" clearable type="textarea"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增岗位',
					edit: '编辑岗位',
					show: '查看岗位'
				},
				visible: false,
				isSaveing: false,
				menuExpand: false,
				menuNodeAll: false,
				//表单数据
				form: {
					postId:undefined
				},
				//验证规则
				rules: {
					postName: [
						{required: true, message: '请输入岗位名称'}
					],
					postCode: [
						{required: true, message: '请输入岗位别名'}
					]
				},
				apiObj: this.$API.mock.page,
				params: {
					name: 'demoName'
				},
				value: [
					{
						id: "410000199512025445",
						user: "魏磊"
					},
					{
						id: "520000198407304275",
						user: "史平"
					}
				],
				value2: {
					id: "520000198407304275",
					user: "史平"
				},
				props: {
					label: 'user',
					value: 'id',
					keyword: "keyword"
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if (valid) {
						this.isSaveing = true;
						let res = null;
						if (typeof (this.form.postId) =='undefined'){
							 res = await this.$API.system.post.savePost.post(this.form);
						}else {
							 res = await this.$API.system.post.updatePost.put(this.form);
						}
						this.isSaveing = false;
						if(res.code == 200){
							this.$emit('success', this.form, this.mode)
							this.visible = false;
							this.$message.success("操作成功")
						}else{
							this.$alert(res.msg, "提示", {type: 'error'})
						}
					}
				})
			},
			//表单注入数据
			async setData(data) {
				//可以和上面一样单个注入，也可以像下面一样直接合并进去
				Object.assign(this.form, data)
			}
		}
	}
</script>

<style>
.tree-border {
	width: 100%;
	height: 200px;
	overflow-y: scroll;
	margin-top: 5px;
	border: 1px solid #e5e6e7;
	background: #FFFFFF none;
	border-radius:4px;
}

</style>
